#include "videoplayer.h"

VideoPlayer* VideoPlayer::instance = 0;

VideoPlayer::VideoPlayer() : QVideoWidget()
{
    player = new QMediaPlayer(this);
    player->setVideoOutput(this);

    setMinimumSize(600, 400);
    show();
    connect(NetworkCommunicator::instance(), SIGNAL(newStreamUrlFound(QUrl)), this, SLOT(playSong(QUrl)));
}

VideoPlayer* VideoPlayer::get()
{
    if(instance == NULL)
        instance = new VideoPlayer;
    return instance;
}

void VideoPlayer::playSong(QUrl streamUrl)
{
    qDebug("starting play");
    streamUrl = QUrl(streamUrl.toString().remove("url="));
    qDebug(streamUrl.toString().toStdString().c_str());
    player->setMedia(streamUrl);
    //player->setMedia(QUrl::fromLocalFile("C:/Users/Xander/Videos/Box2D.wmv"));
    //player->setMedia(QUrl::fromLocalFile("C:/Users/Xander/Downloads/Ghost.Adventures.Season.3.Complete.HDTV.720p-tNe/Ghost.Adventures.S03E03.Poveglia.Island.HDTV.720p-tNe"));
    player->play();
    player->setPlaybackRate(20);
}
